#include "stdafx.h"
#include "MainMenuState.h"

MainMenuState::MainMenuState(Ogre::Root* root) {
	m_mCtrl = NULL;
	r = root;
}

MainMenuState::~MainMenuState() {
	sceneMgr->clearScene();
    w->removeAllViewports();
	delete m_controllers;
	delete model;
	m_controllers = NULL;
	r->destroySceneManager(sceneMgr);
}

void MainMenuState::initalize(Ogre::RenderWindow* window) {
	w = window;
	sceneMgr = r->createSceneManager("DefaultSceneManager");

	//Create camera
	Ogre::Camera* camera = sceneMgr->createCamera("PlayerCam");
	camera->lookAt(Ogre::Vector3(0,0,300));
	camera->setNearClipDistance(5);
	

	// Create one viewport, entire window
	Ogre::Viewport* vp = w->addViewport(camera);
	vp->setBackgroundColour(Ogre::ColourValue(0,0,0));
 
	// Alter the camera aspect ratio to match the viewport
	camera->setAspectRatio(
		Ogre::Real(vp->getActualWidth()) / Ogre::Real(vp->getActualHeight()));
	
	model = new Model(sceneMgr);
	this->setModel(model);

	// Create and add the GUI Controller
	m_gCtrl = new MainMenuGUIController(model, window, "OgreTray", "none");
	this->addController(m_gCtrl);

	// Create and add the music controller
	m_mCtrl = new MusicController(model);
	m_mCtrl->startMusic();
	this->addController(m_mCtrl);

	// Set the ambient light
	sceneMgr->setAmbientLight(Ogre::ColourValue(0, 0, 0));

	//Create sky
	sceneMgr->setSkyBox(true, "Examples/SpaceSkyBox");
	
}

void MainMenuState::addPlayerAvatar(PlayerAvatar* avatar) {
	m_currentModel->addGameObject(avatar, m_currentModel->getNextID(), 0,0,0);
	m_mCtrl->setMainAvatar(avatar);

}

